home *** CD-ROM | disk | FTP | other *** search
- Path: ornews.intel.com!news
- From: thurman_b_miller@ccm2.hf.intel.com (Thurman Miller)
- Newsgroups: comp.lang.c++
- Subject: Re: newbie need help with pointers
- Date: Tue, 09 Jan 1996 18:07:56 GMT
- Organization: Intel Corporation
- Message-ID: <4cub0b$rml@ornews.intel.com>
- References: <4cse34$308@news.iconn.net>
- NNTP-Posting-Host: thurman-pc.ssd.intel.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- thecrow@iconn.net (The Crow) wrote:
-
- >Hey,
- > Ok, I understand what pointers *are*, I know how to declare one, how to
- >use them with simple things and sometimes how to use them to do dynamic memory
- >allocation. I don't feel very comfortable with them yet, nor have I seen any
- >practical example of where they are useful *except* for dynamic memory
- >allocation and in functions...and in arrays, but I am not very comfortable in
- >any of these uses anyway, and can't think of a real problem where it would be
- >advantageous or neccesary to use them. I have also had some trouble using them
- >with STRUCTURE arrays (havent tried classes yet but I assume I will run into
- >similar problems)
-
- > If anyone has a good idea for a programming exercise that would get me
- >familiar with pointers tell me. My tutorial's exercises are way too easy. If
- >it was an interesting one that would be nice, but just so I get comfortable
- >with them. I don't really know them well enough to think of a good exercise
- >myself, or I would. Thanks for the help in advance. Please reply via email,
- >this newsgroup grows too fast. Thanks.
-
- >--
- >The Crow - thecrow@iconn.net
- >"It can't rain all the time"
- >-Kryptology
-
- The main reasons for using pointers are so that you don't pass an
- entire structure to a function so it can use it. Strings are a good
- example in that you don't want to pass the entire string to a
- function, just a pointer to it's location.
-
- If the function is planning on updating the value you are passing,
- then you should use a reference to the variable (&) instead of a
- pointer.
-
- As for some sample tutorials to get used to pointers, try to replace
- any parameters that are large objects (arrays, linked lists, strings)
- by defining a pointer to that type of object and setting that pointer
- to the object and then passing the pointer in the function.
-
- Oh, just thought of a great example of pointers, write some code using
- an array and then change it to be a linked list. You'll need member
- functions GetFirst, GetNext, GetPrev, etc and they should all take
- pointers as arguments (pass in the pointer to the current item and
- they return a pointer to the item in question)
-
- Good luck!
-
- Thurman
-
-
-
-